package spu

import (
	"context"
	"errors"
	"github.com/google/uuid"
	"insighttracking/query/dao"
	"net/http"

	"insighttracking/apps/admin/internal/svc"
	"insighttracking/apps/admin/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
	"os"
)

type DeleteSpuByIdApiLogic struct {
	logx.Logger
	ctx     context.Context
	svcCtx  *svc.ServiceContext
	Request *http.Request
}

func NewDeleteSpuByIdApiLogic(ctx context.Context, svcCtx *svc.ServiceContext, request *http.Request) *DeleteSpuByIdApiLogic {
	hostname, _ := os.Hostname()
	return &DeleteSpuByIdApiLogic{
		Logger: logx.WithContext(ctx).WithCallerSkip(0).WithFields(
			logx.Field("Log_UUID", uuid.New().String()),
			logx.Field("hostname", hostname)),
		ctx:     ctx,
		svcCtx:  svcCtx,
		Request: request,
	}
}

func (l *DeleteSpuByIdApiLogic) DeleteSpuByIdApi(req *types.IdReq) (resp string, err error) {
	if _, err = dao.SpuEntity.WithContext(l.ctx).Where(dao.SpuEntity.ID.Eq(req.Id)).Delete(); err != nil {
		return "", errors.New("删除失败")
	}
	return "删除成功", nil
}
